package cn.diancan.vo.other;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map; 
import java.util.Map.Entry;
import java.util.Set;

/**
 * (苹果)关键词替换
 * @author Sky
 *
 */
public class KeyWordRep {
    
    private static Map<String,String> keys =new HashMap<String,String>();
    private static Map<String,String> keys2 =new HashMap<String,String>();
    
    static{
	put("约饭", "美食品鉴");
	put("陪逛街", "带路党");
	put("聚会", "聚会串场");
	put("伴游", "导游");
	put("一起运动", "健身");
	put("运动", "健身");
	put("陪唱歌", "秀歌声");
	//keys.put("看电影", "看电影");
	put("陪喝酒", "品茶品酒");
	put("陪LOL", "玩LOL");
    }
    
    private static void put(String key,String value){
	keys.put("#"+key+"#", "#"+value+"#");
	keys2.put(key, value);
    }
    
    /**
     * 带#处理
     * @param oldStr
     * @return
     */
    public static String getRepStr(String oldStr){ 
	if(null==oldStr){
	    return null;
	}
	Set< Entry<String,String>> set =keys.entrySet();
	Iterator< Entry<String,String>> iterator = set.iterator();
	while(iterator.hasNext()){
	    Entry<String,String> entry = iterator.next(); 
	    oldStr =oldStr.replaceAll(entry.getKey(), entry.getValue());
	}
	return oldStr;
    }
    
    /**
     * 不带#处理
     * @param oldStr
     * @return
     */
    public static String getRegStr2(String oldStr){
	if(null==oldStr){
	    return null;
	}
	Set< Entry<String,String>> set =keys2.entrySet();
	Iterator< Entry<String,String>> iterator = set.iterator();
	while(iterator.hasNext()){
	    Entry<String,String> entry = iterator.next(); 
	    oldStr =oldStr.replaceAll(entry.getKey(), entry.getValue());
	}
	return oldStr;
    }
    
    public static void main(String[] args) {
	String s="#陪逛街#一起运动#看电影#";
	System.out.println(getRepStr(s));
    }

}
